Skip to content

parens are not optional in guard chains that have || operators#2224

Open
tshepang wants to merge 2 commits intorust-lang:masterfrom
tshepang:patch-2
Open

parens are not optional in guard chains that have || operators#2224
tshepang wants to merge 2 commits intorust-lang:masterfrom
tshepang:patch-2

Conversation

@tshepang
Copy link
Copy Markdown
Member

No description provided.

@rustbot rustbot added the S-waiting-on-review Status: The marked PR is awaiting review from a maintainer label Apr 11, 2026

r[expr.if.chains.or]
If any condition operand is a `let` pattern, then none of the condition operands can be a `||` [lazy boolean operator expression][expr.bool-logic] due to ambiguity and precedence with the `let` scrutinee. If a `||` expression is needed, then parentheses can be used. For example:
If any condition operand is a `let` pattern, then none of the condition operands can be a `||` [lazy boolean operator expression][expr.bool-logic] due to ambiguity and precedence with the `let` scrutinee. If a `||` expression is needed, then parentheses must be used. For example:
Copy link
Copy Markdown
Contributor

@ehuss ehuss Apr 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it is correct to use "must" here. This is saying that this is an option for how to work around the limitation. For example, you could sometimes use curly braces, or lift parts out to a variable, or don't use chains.

I think the correct change would be to move this statement out to an example block like the other one, since it isn't a language rule.

View changes since the review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: The marked PR is awaiting review from a maintainer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants